// ActionScript file
import com.helloniu.data.wb.LineStyle;
import com.helloniu.data.wb.WBStyle;
import com.helloniu.fl.util.StyleTool;
import com.helloniu.fl.util.Tool;

private var lineStyleArr:Array = [
	{label:"Dot", data:1},
	{label:"Arrow", data:2}
	];

private var lineWidthArr:Array = [
	{label:"1", data:1},
	{label:"3", data:3},
	{label:"5", data:5}
	];

private var lineStyle:LineStyle = new LineStyle();
private var lineStyle2:LineStyle = new LineStyle();

private function initComp(e:*):void {
    StyleTool.setBtnStyle(applyBtn, "applyIcon");

    lineStyleCombo.dataProvider = lineStyleArr;
    lineWidthCombo.dataProvider = lineWidthArr;
}

public function populate():void {	
	lineStyleCombo.selectedIndex = lineStyle.lineStyle - 1;
    lineWidthCombo.selectedIndex = ((lineStyle.lineWidth - 1)/2 as int);
    lineColor.selectedColor = lineStyle.lineColor.color;
    lineAlpha.text = "" + (lineStyle.lineColor.alpha*100 as int);
}

public function update():void {	
    lineStyle2.lineStyle = lineStyleCombo.selectedItem.data;
    lineStyle2.lineWidth = lineWidthCombo.selectedItem.data;
    lineStyle2.lineColor.color = lineColor.selectedColor;
    lineStyle2.lineColor.alpha = Tool.toAlpha(parseInt(lineAlpha.text));//0~1? 0~~100??

    // @temp tonyy
    // fire ModifyEvent()
}

public function getWBStyle():WBStyle {
	update();

	return lineStyle2;
}

public function setWBStyle(awbstyle:WBStyle):void {
	lineStyle = awbstyle as LineStyle;	
}	

override protected function updateDisplayList(w:Number, h:Number):void {
	super.updateDisplayList(w, h);
	
	if(w > 0 && h > 0) {
		populate();
	}	
}